import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-05-22
 * Time: 15:59
 */
class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Test {

    public static void main(String[] args) {
        try(Scanner scanner = new Scanner(System.in);){
            int n = scanner.nextInt();
            System.out.println(n);
        }catch(InputMismatchException e){
            e.printStackTrace();
            System.out.println("输入的数据不匹配");
        }finally {
            System.out.println("执行了finally部分 一般用来关闭资源");
        }
    }

    public static void test2(int a){
        try{
            if(a == 10){
                throw new CloneNotSupportedException();//受查异常 此时必须处理
            }
            System.out.println("1");
        }catch(CloneNotSupportedException e){
            e.printStackTrace();
        }
        System.out.println("11111");
    }

    public static void test1(int a){
        try{
            if(a == 10){
                throw new NullPointerException();
            }
        }catch(NullPointerException e){
            e.printStackTrace();
        }
        System.out.println("1");
    }

    //此时不算处理异常
    public static void test22(int a) throws CloneNotSupportedException, ArrayIndexOutOfBoundsException, NullPointerException {
        if(a == 10){
            throw new CloneNotSupportedException();//受查异常 此时必须处理
        }
        System.out.println("11111");
    }

    public static void main11(String[] args) {
        try{
            test22(10);
        }catch(CloneNotSupportedException e){
            e.printStackTrace();
        }
        System.out.println("2");

        /*int x = 10;
        if(x == 10){
            throw new Exception();//默认是受查异常
        }*/
    }

    public static void main10(String[] args) throws CloneNotSupportedException {
        test22(10);
        System.out.println("2");
    }

    public static void main9(String[] args) {
        try{
            test1(10);
        }catch(NullPointerException e){
            e.printStackTrace();
        }
        System.out.println("haha");
    }

    public static void main8(String[] args) {
        try {
            //System.out.println(10/0);
            int[] array = {1, 2, 3, 4};
            array = null;
            System.out.println(array[10]);
        } catch (ArithmeticException e) {
            e.printStackTrace();//快速定位异常出现的位置
            System.out.println("这里出现算术异常");
        } catch (NullPointerException e) {
            e.printStackTrace();
            System.out.println("捕捉到了空指针异常");
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("数组越界异常");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("执行后续代码");
    }

    public static void main7(String[] args) {
        try{
            System.out.println(10/0);
            int[] array = {1,2,3,4};
            array = null;
            System.out.println(array[10]);
        }catch(Exception e){
            e.printStackTrace();//快速定位异常出现的位置
            System.out.println("这里出现异常");
        }
        System.out.println("执行后续代码");
    }

    public static void main6(String[] args) {
        try{
            //System.out.println(10/0);
            int[] array = {1,2,3,4};
            array = null;
            System.out.println(array[10]);
        }catch(ArithmeticException | NullPointerException | ArrayIndexOutOfBoundsException e){
            e.printStackTrace();//快速定位异常出现的位置
            //System.out.println("这里出现异常");
        }
        System.out.println("执行后续代码");
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[10]);
    }

    public static void main4(String[] args) {

        try{
            //System.out.println(10/0);
            int[] array = {1,2,3,4};
            array = null;
            System.out.println(array[0]);

            System.out.println("fsfdasfasd");
        }catch(ArithmeticException e){
            e.printStackTrace();//快速定位异常出现的位置
            System.out.println("这里出现算术异常");
        }catch(NullPointerException e){
            e.printStackTrace();
            System.out.println("捕捉到了空指针异常");
        }catch(ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("数组越界异常");
        }
        System.out.println("执行后续代码");

        /*try{
            System.out.println(10/0);
        }catch(NullPointerException e){
            System.out.println("这里出现算术异常");
        }
        System.out.println("执行后续代码");*/

        /*try{
            System.out.println(10/0);
        }catch(ArithmeticException e){
            System.out.println("这里出现算术异常");
        }
        System.out.println("执行后续代码");*/

        /*System.out.println(10/0);
        //当程序出现异常时 程序终止

        System.out.println("执行后续代码");*/
    }

    public static void func(){
        func();
    }
    public static void main3(String[] args) {
        func();
        //Exception in thread "main" java.lang.StackOverflowError
        //栈溢出错误
    }

    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person = new Person();
        Person person1 = (Person) person.clone();
    }

    public static void main1(String[] args) {
        /*System.out.println(10/0);
        //Exception in thread "main" java.lang.ArithmeticException: / by zero
        //算数异常*/

        /*int[] arr ={1,2,3};
        System.out.println(arr[100]);
        //Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
        //数组越界异常*/

        /*int[] arr = null;
        System.out.println(arr.length);
        //Exception in thread "main" java.lang.NullPointerException
        //空指针异常*/

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(n);

    }
}
